package com.lovo.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.web.bean.UserOrderBean;
import com.lovo.web.service.IUserOrderService;
import com.lovo.web.vo.DepositVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IUserOrderService orderService;

    @RequestMapping("findAllByBuyerName/{pageNO}/{buyerName}/{status}")
    public IPage<UserOrderBean> findAllByBuyerName(@PathVariable("pageNO") int pageNO, @PathVariable("buyerName") String buyerName, @PathVariable("status") int status) {
        return orderService.findAllByBuyerName(pageNO, buyerName, status);
    }

    @RequestMapping("del/{orderId}")
    public String del(@PathVariable("orderId") long orderId) {
        orderService.del(orderId);
        return "ok";
    }

    @RequestMapping("pay")
    public String pay(@RequestBody DepositVo depositVo) {
        orderService.pay(depositVo);
        return "ok";
    }

    @RequestMapping("updateStatus/{orderNum}/{status}/{reason}")
    public String updateStatus(@PathVariable("orderNum") String orderNum, @PathVariable("status") int status, @PathVariable("reason") String reason) {
        orderService.updateStatus(orderNum, status, reason);
        return "ok";
    }

    @RequestMapping("updateStatusRemote/{orderNum}/{status}")
    public String updateStatusRemote(@PathVariable("orderNum") String orderNum, @PathVariable("status") int status) {
        orderService.updateStatusRemote(orderNum, status);
        return "ok";
    }

    @RequestMapping("/updateRefund/{orderNum}/{status}/{updateDate}/{adminName}")
    public boolean updateRefund(String orderNum, int status, String updateDate, String adminName) {
        orderService.updateRefund(orderNum, status, LocalDate.parse(updateDate), adminName);
        return true;
    }

    ;
}
